﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using App.Domain;
using App.Web.ViewModels;
using App.Web.Utility;
using AutoMapper;
using App.Search;

namespace App.Web.Areas.Admin.Controllers
{
    [Authorize(Roles = "Admin")]
    public class SearchConfigController : BaseController
    {
		private AppEntities _Context = new AppEntities();
        
		public SearchConfigController()
		{
		}

		public SearchConfigController(UserViewModel currentUser)
			: base(currentUser)
        {
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult SearchIndexStatus()
        {            
            return View();
        }
        /// <summary>
        /// Deletes all products (if any) from Lucene Index and DB Index and after that Re-Indexes them
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SearchIndexStatus(String dateTime)
        {
            ProductIndexManager indexManager = new ProductIndexManager();
            ReIndexResult result = indexManager.ReIndex();
            ///Reload the Index searcher, to immediately availabe by the index searcher.
            ProductSearchManager.Reload();
            ViewData[AppConstants.ViewDataKeys.SAVED] = result;
            return View();
        }        
    }
}
